﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SimpleSaas.Common.DataBase
/// <summary>
/// 版 本 钢易智企2.0 V 2.0.0 钢易智企2.0
/// Copyright (c) 2023 杭州钢易科技有限公司
/// 创建人：曾东明
/// 日 期：2024
/// 描 述：
/// </summary>
{
	public interface IBaseRepository<TEntity, Tkey>
	{
		/// <summary>
		/// 添加 并且返回实体
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public Task<TEntity> CreateReturnEntityAsync(TEntity entity);

		/// <summary>
		/// 添加 
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public Task<int> CreateReturnIdentityAsync(TEntity entity);

		/// <summary>
		/// 创建数据
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public Task<bool> CreateAsync(TEntity entity);

		/// <summary>
		/// 创建集合
		/// </summary>
		/// <param name="entitys"></param>
		/// <returns></returns>
		public Task<bool> CreateAsync(List<TEntity> entitys);


		/// <summary>
		/// 更新实体
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public Task<bool> UpdateAsync(TEntity entity);

		/// <summary>
		/// 更新集合
		/// </summary>
		/// <param name="entitys"></param>
		/// <returns></returns>
		public Task<bool> UpdateAsync(List<TEntity> entitys);

		/// <summary>
		/// 删除实体
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> lamada);

		/// <summary>
		/// 软删除
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<bool> SoftDeleteAsync(Expression<Func<TEntity, bool>> lamada);

		/// <summary>
		/// 软删除
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<bool> SoftDeleteAsync(TEntity entity);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="expression"></param>
		/// <returns></returns>
		public ISugarQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="expression"></param>
		/// <returns></returns>
		public Task<int> CountAsync(Expression<Func<TEntity, bool>> expression);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<bool> AnyAsync(Expression<Func<TEntity, bool>> lamada);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> lamada);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="lamada"></param>
		/// <param name="currentPage"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public Task<IEnumerable<TEntity>> SelectAsync(Expression<Func<TEntity, bool>> lamada, int currentPage = 0, int pageSize = 20);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="lamada"></param>
		/// <param name="currentPage"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public IEnumerable<TEntity> Select(Expression<Func<TEntity, bool>> lamada, int currentPage = 0, int pageSize = 20);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="lamada"></param>
		/// <returns></returns>
		public Task<TEntity> SingleOrDefaultAsync(Expression<Func<TEntity, bool>> lamada);

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public Task<int> SaveQueuesAsync();

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public int SaveChanges();
		/// <summary>
		/// 
		/// </summary>
		public void EnableLogger();
	}
}
